package com.my12306.user.controller.auth;

import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.user.model.po.auth.RolePermissionEntity;
import com.my12306.user.service.auth.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @Author:苏牧夕
 * @Date:2020-05-15 17:36:13
 * @Version 1.0
 */
@RestController
@RequestMapping("auth/rolepermission")
public class RolePermissionController {
    @Autowired
    private RolePermissionService rolePermissionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("article:oauthrolepermission:list")
    public ResponseData list(@RequestParam Map<String, Object> params) {
        PageUtils page = rolePermissionService.queryPage(params);

        return ResponseData.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("article:oauthrolepermission:info")
    public ResponseData info(@PathVariable("id") Long id) {
        RolePermissionEntity oauthRolePermission = rolePermissionService.getById(id);

        return ResponseData.ok().put("oauthRolePermission", oauthRolePermission);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("article:oauthrolepermission:save")
    public ResponseData save(@RequestBody RolePermissionEntity oauthRolePermission) {
        rolePermissionService.save(oauthRolePermission);

        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("article:oauthrolepermission:update")
    public ResponseData update(@RequestBody RolePermissionEntity oauthRolePermission) {
        rolePermissionService.updateById(oauthRolePermission);

        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("article:oauthrolepermission:delete")
    public ResponseData delete(@RequestBody Long[] ids) {
        rolePermissionService.removeByIds(Arrays.asList(ids));

        return ResponseData.ok();
    }

}
